﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Windows.Forms;
using YArchitech.Controls;
using YArchitech.LIB;
using YArchitech.LIB.YJKControls;

namespace YArchitech.Temp
{
	internal partial class DuctModifyForm : System.Windows.Forms.Form
	{
		public DuctModifyForm()
		{
			this.InitializeComponent();
			new YJKProcessTools().ShowInTaskbarChange(this);
			base.Icon = Resource.YArchitechIcon;
			base.CenterToParent();
			this.ModifyFlow = false;
			this.ModifyWidth = false;
			this.ModifyHeight = false;
		}

		public bool ModifyFlow { get; set; }

		public bool ModifyWidth { get; set; }

		public bool ModifyHeight { get; set; }

		public double Flow { get; set; }

		public int SectionHeight { get; set; }

		public int SectionWidth { get; set; }

		public DuctModifyForm(HYDuctStraight straight, HYDuctSystemDocument doc) : this()
		{
			this.m_Document = doc;
			this.m_DuctStraight = new HYDuctStraight();
			this.m_DuctStraight = straight;
			this.SetFlow(this.m_DuctStraight.Flow);
			if (this.m_DuctStraight.Shape == HYShapeProfile.Round)
			{
				this.checkBoxHeight.Enabled = false;
				this.hyComboBoxHeight.Enabled = false;
				SortedSet<int> sortedSet;
				this.m_Document.Rounds.GetAllWidth(out sortedSet);
				using (SortedSet<int>.Enumerator enumerator = sortedSet.GetEnumerator())
				{
					while (enumerator.MoveNext())
					{
						int num = enumerator.Current;
						this.hyComboBoxWidth.AddItem(num.ToString());
					}
					goto IL_151;
				}
			}
			SortedSet<int> sortedSet2;
			doc.Rects.GetAllWidth(out sortedSet2);
			SortedSet<int> sortedSet3;
			doc.Rects.GetAllWidth(out sortedSet3);
			foreach (int num2 in sortedSet2)
			{
				this.hyComboBoxWidth.AddItem(num2.ToString());
			}
			foreach (int num3 in sortedSet3)
			{
				this.hyComboBoxHeight.AddItem(num3.ToString());
			}
			this.hyComboBoxHeight.SetValue(this.m_DuctStraight.Height);
			IL_151:
			this.hyComboBoxWidth.SetValue(this.m_DuctStraight.Width);
			this.hyTextBoxLength.SetValue(this.m_DuctStraight.Length);
			this.UpdateResult(false);
		}

		private void SetFlow(double flow)
		{
			this.hyTextBoxFlow.SetValue(flow * 3600.0);
		}

		private double GetFlow()
		{
			return this.hyTextBoxFlow.GetValue(this.m_DuctStraight.Flow * 3600.0) / 3600.0;
		}

		private void UpdateResult(bool cal = true)
		{
			if (cal)
			{
				this.m_DuctStraight.Cal(this.m_Document.Option);
			}
			this.hyTextBoxVelocity.SetValue(this.m_DuctStraight.Velocity);
			this.hyTextBoxRm.SetValue(this.m_DuctStraight.Rm);
			this.hyTextBoxCoefficient.SetValue(this.m_DuctStraight.Coefficient);
			this.hyTextBoxPl.SetValue(this.m_DuctStraight.FrictionalResistance);
			this.hyTextBoxPd.SetValue(this.m_DuctStraight.ShockResistance);
			this.hyTextBoxP.SetValue(this.m_DuctStraight.Resistance);
		}

		private void hyTextBoxFlow_TextChanged(object sender, EventArgs e)
		{
			this.m_DuctStraight.Flow = this.GetFlow();
			this.UpdateResult(true);
		}

		private void buttonModify_Click(object sender, EventArgs e)
		{
			this.ModifyFlow = this.checkBoxFlow.Checked;
			this.ModifyHeight = this.checkBoxHeight.Checked;
			this.ModifyWidth = this.checkBoxWidth.Checked;
			this.Flow = this.GetFlow();
			this.SectionWidth = this.hyComboBoxWidth.GetValue(0);
			this.SectionHeight = this.hyComboBoxHeight.GetValue(0);
			base.DialogResult = DialogResult.OK;
		}

		private void hyComboBoxWidth_textChanged(object sender, EventArgs e)
		{
			this.m_DuctStraight.Width = this.hyComboBoxWidth.GetValue(this.m_DuctStraight.Width);
			this.UpdateResult(true);
		}

		private void hyComboBoxHeight_textChanged(object sender, EventArgs e)
		{
			this.m_DuctStraight.Height = this.hyComboBoxWidth.GetValue(this.m_DuctStraight.Height);
			this.UpdateResult(true);
		}

		private void checkBoxFlow_CheckedChanged(object sender, EventArgs e)
		{
			this.hyTextBoxFlow.Enabled = this.checkBoxFlow.Checked;
		}

		private void checkBoxWidth_CheckedChanged(object sender, EventArgs e)
		{
			this.hyComboBoxWidth.Enabled = this.checkBoxWidth.Checked;
		}

		private void checkBoxHeight_CheckedChanged(object sender, EventArgs e)
		{
			this.hyComboBoxHeight.Enabled = this.checkBoxHeight.Checked;
		}

		private HYDuctStraight m_DuctStraight;

		private HYDuctSystemDocument m_Document;
	}
}
